<template>
  <view v-if="listData && listData.length">
    <view v-if="!isOldStyle" class="card-facility" :style="`${styles}`">
      <view class="card-facility-title">
        <text>特色服务 </text>
        <view @click="handleClickMore">更多 <img src="https://zjcl-ywpt.oss-cn-hangzhou-zwynet-d01-a.internet.cloud.zj.gov.cn/zlb-zhzc/zhzc-arrow.png" alt=""> </view>
      </view>

      <view class="card-facility-list" :style="{ 'background': listData[0].bgcolor }">
        <view class="card-facility-list-item" v-for="(item, index) in listData" :key="index"
          @click="handleItemClick(item)">
        
          <svg  v-if="!item.icon.includes('http')" class="icon" aria-hidden="true">
              <use :xlink:href="'#' + item.icon" />
            </svg>
            <img v-else :src="item.icon" alt="" class="icon">
          <text>{{ item.alias?item.alias:item.name }}</text>
        </view>
      </view>

    </view>
  </view>
</template>


<script lang="ts" setup>
import { ref } from "vue";
const props = defineProps({
  styles: String,
  isOldStyle: Boolean,
  matterList: Array
})
let styles = ref('')
if (props.styles) {
  styles.value = props.styles?.replace(/"/g, '');
}

const listData = ref([])
listData.value = props.matterList.filter((val) => {
  return val.type.includes('6')
})


const emit = defineEmits(['handleClick','handleClickMore'])
const handleItemClick = (item: any) => {
  emit('handleClick', {
    url: item.url,
    type: item.type,
    phone: item.phone,
    content: item.name
  })
}

const handleClickMore = () => {
  emit('handleClickMore', {
    type: 'facility'
  })
}


</script>

<style lang="scss" scoped>
.card-facility {
  width: 650upx;
  height: auto;
  border-radius: 12px;
  background-color: rgba(255, 255, 255, 1);
  color: rgba(16, 16, 16, 1);
  font-size: 14px;
  margin: 0 auto;
  margin-top: 24upx;
  position: relative;
  overflow: hidden;
  padding: 20upx;

  .card-facility-title {
    color: rgba(54, 58, 68, 1);
    font-size: 36upx;
    font-weight: bold;
    display: flex;
    justify-content: space-between;

    view {
      font-size: 24upx;
      height: 42upx;
      color: #686B73;
      font-weight: normal;
      display: flex;
      align-items: center;

      img {
        width: 28upx;
        height: 28upx;
        margin-left: 5upx;
      }
    }
  }

  .card-facility-list {
    display: flex;
    justify-content: space-around;
    margin: 32upx 0 0px auto;
    flex-wrap: wrap;
    border-radius: 15px;

    .card-facility-list-item {
      display: flex;
      align-items: center;
      flex-direction: column;
      width: 25%;
      padding:24upx 0;

      .icon {
        width: 60upx;
        height: 60upx;
      }

      text {
        font-size: 24upx;
        color: #101010;
        margin-top: 8upx;
      }
    }
  }


}
</style>